package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/4/7 16:36
 */
public class M0204 {

    // https://leetcode-cn.com/problems/partition-list-lcci/
    public ListNode partition(ListNode head, int x) {
        // 小于放左边, >= 放右边
        ListNode small =new ListNode(-1),
                large = new ListNode(-1);
        ListNode smallHead = small;
        ListNode largeHead = large;
        while (head != null) {
            if (head.val < x) {
                small.next = head;
                small = small.next;
            } else {
                large.next = head;
                large = large.next;
            }
            head = head.next;
        }
        large.next = null;
        small.next = largeHead.next;
        return smallHead.next;
    }

}
